﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IMLibrary.BinaryPacket
{ 
    /// 协议格式：  图片包索引(PakIndex) + 图片索引Index + 是否重复包IsExsit + 重复图片索引ExsitIndex +   是否旧图片ExsitIsOld  +  包内容(Block=BaseData)
    /// 数据长度：     1字节             +   1字节       +   1字节           +         1字节          +             1字节       +       动态
 
    /// <summary>
    /// 远程协助图片包
    /// </summary>
    public class ImagePacket : BasePacket 
    {
        /// <summary>
        /// 基础包长度
        /// </summary>
        public static readonly int HeaderLength = 5;

        /// <summary>
        /// 
        /// </summary>
        public ImagePacket( )
            : base(HeaderLength)
        {
             
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        public  ImagePacket(byte[] data)
            : base(data, HeaderLength)
        {
 
        }

        #region 协议类型
        /// <summary>
        /// 协议类型
        /// </summary>
        public byte CommandType
        {
            set
            {
                Buffer.SetByte(BaseData, 0, value);
            }
            get
            {
                return Buffer.GetByte(BaseData, 0);
            }
        }
        #endregion 

        #region 图片索引
        /// <summary>
        /// 图片索引
        /// </summary>
        public byte Index
        {
            set
            {
                Buffer.SetByte(BaseData, 1, value);
            }
            get
            {
                return Buffer.GetByte(BaseData, 1);
            }
        }
        #endregion

        #region 是否重复包
        /// <summary>
        /// 是否重复包
        /// </summary>
        public bool IsExsit
        {
            set
            {
                if (value)
                    Buffer.SetByte(BaseData, 2, 1);
                else
                    Buffer.SetByte(BaseData, 2, 0);
            }
            get
            {
                if (Buffer.GetByte(BaseData, 2) == 0)
                    return false;
                else
                    return true;
            }
        }
        #endregion

        #region 重复图片索引
        /// <summary>
        /// 重复图片索引
        /// </summary>
        public byte ExsitIndex
        {
            set
            {
                Buffer.SetByte(BaseData, 3, value);
            }
            get
            {
                return Buffer.GetByte(BaseData, 3);
            }
        }
        #endregion

        #region 重复的图片是否旧图片
        /// <summary>
        /// 重复的图片是否旧图片
        /// </summary>
        public bool ExsitIsOld
        {
            set
            {
                if (value)
                    Buffer.SetByte(BaseData, 4, 1);
                else
                    Buffer.SetByte(BaseData, 4, 0);
            }
            get
            {
                if (Buffer.GetByte(BaseData, 4) == 0)
                    return false;
                else
                    return true;
            }
        }
        #endregion
    }

}

